package com.example.elm.Messages


import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.elm.databinding.MessageSettingBinding


class Message_SettingActivity : AppCompatActivity() {
    private lateinit var binding: MessageSettingBinding
    private val sharedPreferences1 by lazy { getSharedPreferences("message_settings1", MODE_PRIVATE) }
    private val sharedPreferences2 by lazy { getSharedPreferences("message_settings2", MODE_PRIVATE) }
    private val sharedPreferences3 by lazy { getSharedPreferences("message_settings3", MODE_PRIVATE) }
    private val sharedPreferences4 by lazy { getSharedPreferences("message_settings4", MODE_PRIVATE) }
    private val sharedPreferences5 by lazy { getSharedPreferences("message_settings5", MODE_PRIVATE) }
    private val sharedPreferences6 by lazy { getSharedPreferences("message_settings6", MODE_PRIVATE) }
    private val sharedPreferences7 by lazy { getSharedPreferences("message_settings7", MODE_PRIVATE) }
    private val sharedPreferences8 by lazy { getSharedPreferences("message_settings8", MODE_PRIVATE) }
    private val sharedPreferences9 by lazy { getSharedPreferences("message_settings9", MODE_PRIVATE) }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = MessageSettingBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.messageBack.setOnClickListener {
            finish()
        }
        val isSwitchChecked1 = sharedPreferences1.getBoolean("switch_state1", false)
        val isSwitchChecked2 = sharedPreferences2.getBoolean("switch_state2", false)
        val isSwitchChecked3 = sharedPreferences3.getBoolean("switch_state3", false)
        val isSwitchChecked4 = sharedPreferences4.getBoolean("switch_state4", false)
        val isSwitchChecked5 = sharedPreferences5.getBoolean("switch_state5", false)
        val isSwitchChecked6 = sharedPreferences6.getBoolean("switch_state6", false)
        val isSwitchChecked7 = sharedPreferences7.getBoolean("switch_state7", false)
        val isSwitchChecked8 = sharedPreferences8.getBoolean("switch_state8", false)
        val isSwitchChecked9 = sharedPreferences9.getBoolean("switch_state9", false)
        binding.messageSwitch1.isChecked = isSwitchChecked1
        binding.messageSwitch1.setOnCheckedChangeListener { compoundButton , b ->
            sharedPreferences1.edit().putBoolean("switch_state1", b).apply()
        }
        binding.messageSwitch2.isChecked = isSwitchChecked2
        binding.messageSwitch2.setOnCheckedChangeListener { compoundButton , b ->
            sharedPreferences2.edit().putBoolean("switch_state2", b).apply()
        }
        binding.messageSwitch3.isChecked = isSwitchChecked3
        binding.messageSwitch3.setOnCheckedChangeListener { compoundButton , b ->
            sharedPreferences3.edit().putBoolean("switch_state3", b).apply()
        }
        binding.messageSwitch4.isChecked = isSwitchChecked4
        binding.messageSwitch4.setOnCheckedChangeListener { compoundButton , b ->
            sharedPreferences4.edit().putBoolean("switch_state4", b).apply()
        }
        binding.messageSwitch5.isChecked = isSwitchChecked5
        binding.messageSwitch5.setOnCheckedChangeListener { compoundButton , b ->
            sharedPreferences5.edit().putBoolean("switch_state5", b).apply()
        }
        binding.messageSwitch6.isChecked = isSwitchChecked6
        binding.messageSwitch6.setOnCheckedChangeListener { compoundButton , b ->
            sharedPreferences6.edit().putBoolean("switch_state6", b).apply()
        }
        binding.messageSwitch7.isChecked = isSwitchChecked7
        binding.messageSwitch7.setOnCheckedChangeListener { compoundButton , b ->
            sharedPreferences7.edit().putBoolean("switch_state7", b).apply()
        }
        binding.messageSwitch8.isChecked = isSwitchChecked8
        binding.messageSwitch8.setOnCheckedChangeListener { compoundButton , b ->
            sharedPreferences8.edit().putBoolean("switch_state8", b).apply()
        }
        binding.messageSwitch9.isChecked = isSwitchChecked9
        binding.messageSwitch9.setOnCheckedChangeListener { compoundButton , b ->
            sharedPreferences9.edit().putBoolean("switch_state9", b).apply()
        }
    }
}